/*
 * Copyright (C) 2009 Rafael Fernandes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phonebooksharing.android.provider;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import com.phonebooksharing.android.provider.PhonebookSharing.Dashboard;
import com.phonebooksharing.android.provider.PhonebookSharing.DashboardSync;
import com.phonebooksharing.android.provider.PhonebookSharing.DesktopMessage;
import com.phonebooksharing.android.provider.PhonebookSharing.DesktopWidgets;
import com.phonebooksharing.android.provider.PhonebookSharing.Message;
import com.phonebooksharing.android.provider.PhonebookSharing.SendTo;
import com.phonebooksharing.android.provider.PhonebookSharing.Settings;
import com.phonebooksharing.android.provider.PhonebookSharing.Sync;
import com.phonebooksharing.android.util.Global;

public final class PhonebookSharingProvider extends ContentProvider {
    private static final String DATABASE_NAME = "pbs.db";
    private static final int DATABASE_VERSION = 1;

    private DBHelper dbHelper;
    private static final UriMatcher URI_MATCHER;
    
    @Override
    public boolean onCreate() {
        dbHelper = new DBHelper(getContext());
        return true;
    }
    
    /**
     * Figure out which query to run based on the URL requested and
     * any other parameters provided.
     */
    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
            String[] selectionArgs, String sort) {
        // Query the database using the arguments provided
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        switch (URI_MATCHER.match(uri)) {
            
            case MYINBOX_MATCHER: {
                qb.setTables(MYINBOX_TABLE_NAME);
                break;
            }
            case SETTINGS_MATCHER: {
                qb.setTables(SETTINGS_TABLE_NAME);
                break;
            }
            case SYNC_MATCHER: {
                qb.setTables(SYNC_TABLE_NAME);
                break;
            }
            case DASHBOARD_SYNC_MATCHER: {
                qb.setTables(DASHBOARD_SYNC_TABLE_NAME);
                break;
            }
            case SYNC_MATCHER_ID: {
                qb.setTables(SYNC_TABLE_NAME);
                qb.appendWhere(Sync._ID + "=" + uri.getPathSegments().get(1));
                break;
            }
            case MSG_SYNC_MATCHER: {
                qb.setTables(MSG_SYNC_TABLE_NAME);
                break;
            }
            case MSG_SYNC_MATCHER_ID: {
                qb.setTables(MSG_SYNC_TABLE_NAME);
                qb.appendWhere(Message._ID + "=" + uri.getPathSegments().get(1));
                break;
            }
            case MSG_SYNC_MATCHER_SENT_TO: {
                qb.appendWhere(SendTo.RELATE_TABLE + "=" + SendTo.RELATION_TO_MESSAGE + " AND ");
                qb.appendWhere(SendTo.RELATE_ID + "=" + uri.getPathSegments().get(1));
                qb.setTables(SYNC_SENT_TO_TABLE_NAME);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER: {
                qb.setTables(DESKTOP_MSG_TABLE_NAME);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER_ID: {
                qb.setTables(DESKTOP_MSG_TABLE_NAME);
                qb.appendWhere(DesktopMessage._ID + "=" + uri.getPathSegments().get(1));
                break;
            }
            case DESKTOP_WIDGETS_MATCHER: {
                qb.setTables(DESKTOP_WDGT_TABLE_NAME);
                break;
            }
            case DESKTOP_WIDGETS_MATCHER_ID: {
                qb.setTables(DESKTOP_WDGT_TABLE_NAME);
                qb.appendWhere(DesktopWidgets._ID + "=" + uri.getPathSegments().get(1));
                break;
            }
            default:
                // anything else is considered and illegal request
                throw new IllegalArgumentException("Unknown URL " + uri);
        }

        // Run the query and return the results as a Cursor
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sort);
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    }
    
    /**
     * For a given URL, return a MIME type for the data that
     * will be returned from that URL. This will help Android
     * decide what to do with the data it gets back.
     */
    @Override
    public String getType(Uri uri) {
        switch (URI_MATCHER.match(uri)) {
            case MYINBOX_MATCHER:
                return PhonebookSharing.Dashboard.CONTENT_TYPE;
            case SETTINGS_MATCHER:
                return PhonebookSharing.Settings.CONTENT_TYPE;
            case SYNC_MATCHER:
                return PhonebookSharing.Sync.CONTENT_TYPE;
            case SYNC_MATCHER_ID:
                return PhonebookSharing.Sync.CONTENT_ITEM_TYPE;
            case MSG_SYNC_MATCHER:
                return PhonebookSharing.Message.CONTENT_TYPE;
            case MSG_SYNC_MATCHER_ID:
                return PhonebookSharing.Message.CONTENT_ITEM_TYPE;
            case SYNC_SENT_TO_MATCHER:
                return PhonebookSharing.SendTo.CONTENT_TYPE;
            case DASHBOARD_SYNC_MATCHER:
                return PhonebookSharing.DashboardSync.CONTENT_TYPE;
            case DESKTOP_MSG_SYNC_MATCHER:
                return PhonebookSharing.DesktopMessage.CONTENT_TYPE;
            case DESKTOP_MSG_SYNC_MATCHER_ID:
                return PhonebookSharing.DesktopMessage.CONTENT_ITEM_TYPE;
            case DESKTOP_WIDGETS_MATCHER:
                return PhonebookSharing.DesktopWidgets.CONTENT_TYPE;
            case DESKTOP_WIDGETS_MATCHER_ID:
                return PhonebookSharing.DesktopWidgets.CONTENT_ITEM_TYPE;
            default:
                // any other kind of URL is illegal
                throw new IllegalArgumentException("Unknown URL " + uri);
        }
    }
    
    /**
     * For a URL and a list of initial values, insert a row using
     * those values into the database.
     * Should insert only one record at the DB
     */
    @Override
    public Uri insert(Uri uri, ContentValues initialValues) {
        ContentValues values;
        if (initialValues != null) {
            values = new ContentValues(initialValues);
        } else {
            values = new ContentValues();
        }
        
        switch (URI_MATCHER.match(uri)) {
            case MYINBOX_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(MYINBOX_TABLE_NAME, Dashboard.QTY_FRIENDS_NEARBY, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(Dashboard.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case SETTINGS_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(SETTINGS_TABLE_NAME, Settings.AUTH_ID, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(Settings.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case SYNC_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                values.put(Sync.SYNC_TIME, System.currentTimeMillis());//overrides the time
                final long rowId = db.insert(SYNC_TABLE_NAME, Sync.SYNC_TIME, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(Sync.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case MSG_SYNC_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(MSG_SYNC_TABLE_NAME, Message.TYPE, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(Message.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case DASHBOARD_SYNC_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(DASHBOARD_SYNC_TABLE_NAME, DashboardSync.ACTION, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(DashboardSync.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case SYNC_SENT_TO_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(SYNC_SENT_TO_TABLE_NAME, SendTo.SENT_TO_GROUP, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(SendTo.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case DESKTOP_MSG_SYNC_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(DESKTOP_MSG_TABLE_NAME, DesktopMessage.TYPE, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(DesktopMessage.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            case DESKTOP_WIDGETS_MATCHER: {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                final long rowId = db.insert(DESKTOP_WDGT_TABLE_NAME, DesktopWidgets.UPDATE_INTERVAL, values);
                if (rowId > 0) {
                    Uri insertUri = ContentUris.withAppendedId(DesktopWidgets.CONTENT_URI, rowId);
                    getContext().getContentResolver().notifyChange(uri, null);
                    return insertUri;
                }
            }
            default:
                break;
        }
        throw new SQLException("Failed to insert row into " + uri);
    }
    
    /**
     * Delete rows matching the where clause and args for the supplied
     * URL.
     */
    @Override
    public int delete(Uri uri, String where, String[] whereArgs) {
        int count;
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        switch (URI_MATCHER.match(uri)) {
            case SETTINGS_MATCHER: {
                count = db.delete(SETTINGS_TABLE_NAME, where, whereArgs);
                break;
            }
            case MYINBOX_MATCHER: {
                count = db.delete(MYINBOX_TABLE_NAME, where, whereArgs);
                break;
            }
            case SYNC_MATCHER: {
                count = db.delete(SYNC_TABLE_NAME, where, whereArgs);
                break;
            }
            case SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.delete(SYNC_TABLE_NAME, Sync._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case MSG_SYNC_MATCHER: {
                count = db.delete(MSG_SYNC_TABLE_NAME, where, whereArgs);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER: {
                count = db.delete(DESKTOP_MSG_TABLE_NAME, where, whereArgs);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.delete(DESKTOP_MSG_TABLE_NAME, DesktopMessage._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case DESKTOP_WIDGETS_MATCHER: {
                count = db.delete(DESKTOP_WDGT_TABLE_NAME, where, whereArgs);
                break;
            }
            case DESKTOP_WIDGETS_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.delete(DESKTOP_WDGT_TABLE_NAME, DesktopWidgets._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case DASHBOARD_SYNC_MATCHER: {
                count = db.delete(DASHBOARD_SYNC_TABLE_NAME, where, whereArgs);
                break;
            }
            case MSG_SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.delete(MSG_SYNC_TABLE_NAME, Message._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                
                count += db.delete(SYNC_SENT_TO_TABLE_NAME, SendTo.RELATE_TABLE + "=" + SendTo.RELATION_TO_MESSAGE 
                        + " AND " + SendTo.RELATE_ID + "=" + id, null);
                
                break;
            }
            default:
                throw new IllegalArgumentException("Unknown URL " + uri);
        }

        getContext().getContentResolver().notifyChange(uri, null);
        return count;
    }
    
    /**
     * The update method
     */
    @Override
    public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
        int count;
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        switch (URI_MATCHER.match(uri)) {
            case MYINBOX_MATCHER: {
                count = db.update(MYINBOX_TABLE_NAME, values, where, whereArgs);
                break;
            }
            case SYNC_MATCHER: {
                count = db.update(SYNC_TABLE_NAME, values, where, whereArgs);
                break;
            }
            case SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.update(SYNC_TABLE_NAME, values, Sync._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case MSG_SYNC_MATCHER: {
                count = db.update(MSG_SYNC_TABLE_NAME, values, where, whereArgs);
                break;
            }
            case MSG_SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.update(MSG_SYNC_TABLE_NAME, values, Message._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER: {
                count = db.update(DESKTOP_MSG_TABLE_NAME, values, where, whereArgs);
                break;
            }
            case DESKTOP_MSG_SYNC_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.update(DESKTOP_MSG_TABLE_NAME, values, DesktopMessage._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            case DESKTOP_WIDGETS_MATCHER: {
                count = db.update(DESKTOP_WDGT_TABLE_NAME, values, where, whereArgs);
                break;
            }
            case DESKTOP_WIDGETS_MATCHER_ID: {
                String id = uri.getPathSegments().get(1);
                count = db.update(DESKTOP_WDGT_TABLE_NAME, values, DesktopWidgets._ID + "=" + id
                        + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
                break;
            }
            default:
                throw new IllegalArgumentException("Unknown URL " + uri);
        }

        getContext().getContentResolver().notifyChange(uri, null);
        return count;
    }
    
    private static final String MYINBOX_TABLE_NAME = "dsh",
                                SYNC_TABLE_NAME = "syn",
                                MSG_SYNC_TABLE_NAME = "msg",
                                DESKTOP_MSG_TABLE_NAME = "dskmsg",
                                DESKTOP_WDGT_TABLE_NAME = "dskwdgt",
                                SYNC_SENT_TO_TABLE_NAME = "snd",
                                DASHBOARD_SYNC_TABLE_NAME = "dsyn",
                                SETTINGS_TABLE_NAME = "s";

    /**
     * This inner DBHelper class defines methods to create and
     * upgrade the database from previous versions.
     */
    private static class DBHelper extends SQLiteOpenHelper {
        public DBHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);          
        }
        
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE " + MYINBOX_TABLE_NAME + " ("
                            + Dashboard._ID + " INTEGER PRIMARY KEY,"
                            + Dashboard.QTY_FRIENDS_NEARBY + " INTEGER,"
                            + Dashboard.QTY_MESSAGES + " INTEGER,"
                            + Dashboard.QTY_POSTCARDS + " INTEGER,"
                            + Dashboard.QTY_PLACES_NEARBY + " INTEGER,"
                            + Dashboard.QTY_PHOTOS + " INTEGER,"
                            + Dashboard.QTY_VIDEOS + " INTEGER,"
                            + Dashboard.QTY_NON_SHARING_IMAGES + " INTEGER,"
                            + Dashboard.QTY_NON_SHARING_VIDEOS + " INTEGER,"
                            + Dashboard.QTY_JOURNAL + " INTEGER"
                            + ");");
            
            db.execSQL("CREATE TABLE " + SYNC_TABLE_NAME + " ("
                    + Sync._ID + " INTEGER PRIMARY KEY,"
                    + Sync.SYNC_TIME + " INTEGER,"
                    + Sync.SYNC_ADDRESS + " INTEGER,"
                    + Sync.SYNC_LATITUDE + " INTEGER,"
                    + Sync.SYNC_STATUS + " INTEGER,"
                    + Sync.SYNC_TYPE + " INTEGER DEFAULT 0,"
                    + Sync.SYNC_LONGITUDE + " INTEGER"
                    + ");");
            
            db.execSQL("CREATE TABLE " + DASHBOARD_SYNC_TABLE_NAME + " ("
                    + DashboardSync._ID + " INTEGER PRIMARY KEY,"
                    + DashboardSync.ACTION + " INTEGER,"
                    + DashboardSync.DASHBOARD_ITEM_ID + " INTEGER"
                    + ");");
            
            db.execSQL("CREATE TABLE " + MSG_SYNC_TABLE_NAME + " ("
                    + Message._ID + " INTEGER PRIMARY KEY,"
                    + Message.TYPE + " INTEGER,"
                    + Message.TITLE + " TEXT,"
                    + Message.TEXT + " TEXT"
                    + ");");

            db.execSQL("CREATE TABLE " + DESKTOP_MSG_TABLE_NAME + " ("
                    + DesktopMessage._ID + " INTEGER PRIMARY KEY,"
                    + DesktopMessage.TYPE + " INTEGER,"
                    + DesktopMessage.WHEN + " INTEGER,"
                    + DesktopMessage.CONTACT_NAME + " TEXT,"
                    + DesktopMessage.TITLE + " TEXT"
                    + ");");

            db.execSQL("CREATE TABLE " + DESKTOP_WDGT_TABLE_NAME + " ("
                    + DesktopWidgets._ID + " INTEGER PRIMARY KEY,"
                    + DesktopWidgets.UPDATE_INTERVAL + " INTEGER,"
                    + DesktopWidgets.IS_CONFIGURED + " INTEGER"
                    + ");");

            db.execSQL("CREATE TABLE " + SETTINGS_TABLE_NAME + " ("
                    + Settings._ID + " INTEGER PRIMARY KEY,"
                    + Settings.AUTH_ID + " TEXT"
                    + ");");
            
            db.execSQL("CREATE TABLE " + SYNC_SENT_TO_TABLE_NAME + " ("
                    + SendTo._ID + " INTEGER PRIMARY KEY,"
                    + SendTo.GROUP_ID + " INTEGER,"
                    + SendTo.CONTACT_ID + " INTEGER,"
                    + SendTo.RELATE_ID + " INTEGER,"
                    + SendTo.RELATE_TABLE + " INTEGER,"
                    + SendTo.SENT_TO_GROUP + " INTEGER"
                    + ");");
            
            db.execSQL("CREATE INDEX relationIndex ON " + SYNC_SENT_TO_TABLE_NAME + " (" + SendTo.RELATE_TABLE + ", " + SendTo.RELATE_ID + ");");
            
            Global.isNew = true;
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(Global.LOG_TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS " + MYINBOX_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + SYNC_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + MSG_SYNC_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + DESKTOP_MSG_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + DESKTOP_WDGT_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + SYNC_SENT_TO_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + DASHBOARD_SYNC_TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE_NAME);
            
            onCreate(db);
        }
    }
    
    private final static int MYINBOX_MATCHER = 0,
                             SYNC_MATCHER = 1,
                             SYNC_MATCHER_ID = 2,
                             MSG_SYNC_MATCHER = 3,
                             MSG_SYNC_MATCHER_ID = 4,
                             MSG_SYNC_MATCHER_SENT_TO = 5,
                             SYNC_SENT_TO_MATCHER = 6,
                             DASHBOARD_SYNC_MATCHER = 7,
                             SETTINGS_MATCHER = 8,
                             DESKTOP_MSG_SYNC_MATCHER = 9,
                             DESKTOP_MSG_SYNC_MATCHER_ID = 10,
                             DESKTOP_WIDGETS_MATCHER = 11,
                             DESKTOP_WIDGETS_MATCHER_ID = 12
                             ;

    /*
     * This static block sets up the pattern matches for the various URIs that this
     * content provider can handle. It also sets up the default projection block
     * (which defines what columns are returned from the database for the results
     * of a query).
     */
    static {
        URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Dashboard.CONTENT_NAME, MYINBOX_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Sync.CONTENT_NAME, SYNC_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Sync.CONTENT_NAME + "/#", SYNC_MATCHER_ID);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Message.CONTENT_NAME, MSG_SYNC_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Message.CONTENT_NAME + "/#", MSG_SYNC_MATCHER_ID);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Message.CONTENT_NAME + "/#/sendto", MSG_SYNC_MATCHER_SENT_TO);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, SendTo.CONTENT_NAME, SYNC_SENT_TO_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, DashboardSync.CONTENT_NAME, DASHBOARD_SYNC_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, Settings.CONTENT_NAME, SETTINGS_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, DesktopMessage.CONTENT_NAME, DESKTOP_MSG_SYNC_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, DesktopMessage.CONTENT_NAME + "/#", DESKTOP_MSG_SYNC_MATCHER_ID);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, DesktopWidgets.CONTENT_NAME, DESKTOP_WIDGETS_MATCHER);
        URI_MATCHER.addURI(PhonebookSharing.AUTHORITY, DesktopWidgets.CONTENT_NAME + "/#", DESKTOP_WIDGETS_MATCHER_ID);
    }
}
